<script>
  /**
   * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
   */
  import Vue from 'vue';

  export default {
    onLaunch() {
      // 国际化，设置当前语言
      if (this.vuex_locale) {
        this.$i18n.locale = this.vuex_locale;
        this.$u.api.lang({
          lang: this.vuex_locale
        });
      }
      //刷新token
      // uni.getStorage({
      // 	key: 'lifeData',
      // 	success:(res) => {
      // 		if(res.data.vuex_accessToken){
      // 			this.$u.api.refreshToken({
      // 				tenant_id: this.vuex_config.tenantId,
      // 				refresh_token: res.data.vuex_refreshToken,
      // 				grant_type: 'refresh_token',
      // 				scope: "all",
      // 			},{'Role-Id': this.vuex_config.switchMode?this.vuex_roleId:''}).then(res => {
      // 				this.setToken(this, res);
      // 			});
      // 		}
      // 	}
      // });
      //http://localhost:2888/#/?code=111&state=1111&redirect=/mis/mislostfound 单点登录测试链接

      this.addJweixinScript();
    },
    methods: {
      addJweixinScript() {
        window.wx = null;
        const script_jweixin = document.createElement('script');
        script_jweixin.type = 'text/javascript';
        // script_jweixin.src = './static/jweixin/jweixin-1.2.0.js';
        script_jweixin.src = 'http://res.wx.qq.com/open/js/jweixin-1.2.0.js';
        document.head.appendChild(script_jweixin);
        script_jweixin.onload = function() {
          const script_jwxwork = document.createElement('script')
          script_jwxwork.type = 'text/javascript'
          // 下面相对路径会有报错问题，现有则引入在线的js地址
          // script_jwxwork.src= './static/jweixin/jwxwork-1.0.0.js'
          script_jwxwork.src = 'https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js'
          document.head.appendChild(script_jwxwork)
          script_jwxwork.onload = function() {
            Vue.prototype.fjutWeixin = wx;
            uni.fjutWeixin = wx;
          }
        }
      },
      /**
       * 获取重定向地址
       */
      getRedirectUrl() {
        let json = this.$route.query;
        if (json.hasOwnProperty("redirect")) {
          let redirect = this.$route.query.redirect;
          let map = {};
          let params = Object.keys(json).map(function(key) {
            if (key === 'redirect' || key === 'code' || key === 'state') {
              return;
            }
            return key + '=' + json[key];
          }).filter(item => item != undefined).join('&');
          redirect = redirect + '&' + params;
          return redirect;
        }
      }
    }
  }
</script>
<style>
  @import url("~@/static/iconfont/iconfont.css");
</style>
<style lang="scss">
  @import "uview-ui/index.scss";
  @import "pages/common/aidex.scss";
  @import "pages/common/uViewCustStyle.scss";
  @import "pages/common/uniCssOverride.scss";
  
  * {
    box-sizing: border-box;
  }

  uni-page-body {
    height: 100%;
  }
</style>